#pragma once

#include "BasicEvent.h"

namespace events {


/**
 * Special type of event, which indicates end of file, and
 * is always written last. If an output file does not end with
 * <i>EofEvent</i>, it is, probably, corrupted.
 */
class EofEvent : public BasicEvent {
public:
	inline EofEvent(void) : BasicEvent(BasicEvent::EVENT_EOF), _num_events((unsigned long)0) {}
	inline EofEvent(unsigned long num_events) : BasicEvent(BasicEvent::EVENT_EOF), _num_events(num_events) {}

	inline unsigned long getNumOfEvents(void) const { return _num_events(); }
	
	// implementing ISerializable
public:
	virtual void saveToStream(std::ostream &os) const { _num_events.saveToStream(os); }
	virtual void readFromStream(std::istream &is) { _num_events.readFromStream(is); }
	virtual void writeDebugInfo(std::ostream &os) const { os << "EOF (total of " << _num_events() << " events)\n"; }


public:
	/**
	 * As this event is always the last one in the file, it makes sense
	 * to jump directly to the end of the file to read summary info.
	 For this purpose we need to know the size of this final event.
	 */
	static inline unsigned int GetEventLength(void) {
		return (BasicEvent::GetEventHeaderLength() + sizeof(unsigned long));
	}

private:
	GenericDataType<unsigned long> _num_events;
};

}  // end namespace
